package Account;

class Account{
    private String accNo;
    private String accName;
    private double balance;
    static int count = 0;

    public Account() {
    }

    public Account(String accName) {
        count++;
        this.accNo = String.format("SVIP%03d", count);
        this.accName = accName;
    }

    public Account(String accName, double balance) {
        count++;
        this.accNo = String.format("SVIP%03d", count);
        this.accName = accName;
        this.balance = balance;
    }

    public void deposit(double amount) {
        if (amount > 0) {
            System.out.println("存入金额必须大于0");
        }
    }

    public void withdraw(double amount) {
        if (amount > 0 && amount <= this.balance) {
            this.balance -= amount;
            System.out.println("取出金额：" + amount + "，当前余额：" + this.balance);
        } else {
            System.out.println("取款金额无效或余额不足");
        }
    }

    public void printInfo() {
        System.out.println("账号：" + this.accNo + "，账户名：" + this.accName + "，余额：" + this.balance);
    }

    @Override
    public String toString() {
        return "账号：" + this.accNo + "，账户名：" + this.accName + "，余额：" + this.balance;
    }

    public static void main(String[] args) {
        // 定义对象数组，管理5个账户
        Account[] accounts = new Account[5];
        // 为数组赋值
        accounts[0] = new Account("张三", 1000);
        accounts[1] = new Account("李四", 2000);
        accounts[2] = new Account("王五", 3000);
        accounts[3] = new Account("赵六", 4000);
        accounts[4] = new Account("孙七", 5000);

        for (int i = 0; i < accounts.length; i++) {
            System.out.println(accounts[i]);
        }

        for (Account account : accounts) {
            System.out.println(account);
        }
    }
}